<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>退还设备</title>
    <script src="../js/jquery-1.10.2.min.js"></script>
    <link rel="stylesheet" href="../css/refundDevice.css">
</head>
<body>
<div>
    <div id="refund">
        <div data-role="header">
            <div class="title">退还设备</div>
        </div>
        <br>
        <div class="content">
            <div>
                <label for="deviceId"></label>
                <input type="text" maxlength="16" autocomplete="off" placeholder="请输入设备号" id="deviceId">
            </div>
            <br>
            <!--<div>-->
            <!--<label for="unitName"></label>-->
            <!--<input type="text" maxlength="16" autocomplete="off" onblur="checkUnitName(this.id)"-->
            <!--placeholder="请输入单位名"-->
            <!--id="unitName">-->
            <!--</div>-->
            <!--<br>-->
            <div>
                <label for="deviceName"></label>
                <input type="text" maxlength="16" autocomplete="off" onblur="checkDeviceName(this.id)"
                       placeholder="请输入设备名"
                       id="deviceName">
            </div>
            <br>
            <input type="button" class="refundButton" value="退还设备" data-inline="true" onclick="refundDevice()">
        </div>
    </div>
</div>
<script type="text/javascript">
    // function checkUnitName(v) {
    //     if (v == "unitName") {
    //         var unitName = $("#unitName").val();
    //         $.ajax({
    //             type: "post",
    //             url: "/asset/checkUnitName.form?unitName=" + unitName.trim(),
    //             dataType: "html",
    //             success: function (msg) {
    //                 if (msg == "check failure") {
    //                     alert("请输入正确的单位名！");
    //                 }
    //             }
    //         })
    //     }
    // }

    function checkDeviceName(v) {
        if (v == "deviceName") {
            var deviceName = $("#deviceName").val();
            $.ajax({
                type: "post",
                url: "/asset/checkDeviceName.form?deviceName=" + deviceName.trim(),
                dataType: "html",
                success: function (msg) {
                    if (msg == "check failure") {
                        alert("请输入正确的设备名！");
                    }
                }
            })
        }
    }

    function refundDevice() {
        // var unitName = $("#unitName").val();
        var deviceName = $("#deviceName").val();
        var deviceId = $("#deviceId").val();
        $.ajax({
            type: "post",
            url: "/asset/refundDevice.form?deviceName=" + deviceName.trim() + "&deviceId=" + deviceId.trim(),
            dataType: "html",
            success: function (msg) {
                switch (msg) {
                    case  "refund success":
                        alert("退还成功,等待审核");
                        break;
                    case "refund fail":
                        alert("退还申请失败");
                        break;
                    case "useStatus error":
                        alert("使用状态错误");
                        break;
                    default:
                        alert("输入有误");
                }
            }
        })
    }
</script>
</body>
</html>